#!/usr/bin/env bash

# 使用说明　注意修改ＩＰ地址　和　hostname，手动增加hosts
#  未处理的是ｄｏｃｋｅｒ的配置文件　

# 关闭防火墙
systemctl disable firewalld.service 
systemctl stop firewalld.service

swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
setenforce 0
sysctl --system

# 设置系统参数 - 允许路由转发，不对bridge的数据进行处理 ???这个是不是有问题哦
cp ./k8s.conf /etc/sysctl.d/k8s.conf
# 生效配置文件
sysctl -p /etc/sysctl.d/k8s.conf

# 安装ｄｏｃｋｅｒ
yum install -y docker
systemctl enable docker
systemctl start docker

# 关闭 selinu
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux

mkdir /var/lib/kubelet
mkdir /var/log/kubernetes
mkdir /etc/kubernetes
mkdir /etc/kubernetes/ssl

# kubelet
cp ./kubelet.service /usr/lib/systemd/system/kubelet.service 
cp ./kubeconfig.yaml /etc/kubernetes/kubeconfig.yaml


cp ./kube-proxy.service /usr/lib/systemd/system/kube-proxy.service
cp ./proxy /etc/kubernetes/proxy 

# 证书
cp ca.crt ca.key /etc/kubernetes/ssl/
cd /etc/kubernetes/ssl/
openssl genrsa -out kubelet_client.key 2048
openssl req -new -key kubelet_client.key -subj "/CN=192.168.9.190" -out kubelet_client.csr      #  CN指定Node节点的IP
openssl x509 -req -in kubelet_client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out kubelet_client.crt -days 5000


# 服务处理
systemctl daemon-reload
systemctl enable kubelet

systemctl start kubelet

systemctl status kubelet

#　pause镜像准备
docker pull  mirrorgooglecontainers/pause-amd64:3.1
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause-amd64:3.1
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
